using UnityEngine;

public class UIweaponCDcon : MonoBehaviour
{
	public bool recgun;

	public bool recmissile;

	public bool recsinglemissile;

	public bool regunflag;

	public bool remissileflag;

	public bool recsinglemissileflag;

	private float gunintertime;

	private float missileintertime;

	private float singleintertime;

	private float recintertime = 1f;

	public int gun_max;

	public int missile_max;

	public int singlemissile_max;

	public int youdaodan_max;

	public int cur_gun;

	public int cur_missile;

	public int cur_singlemissile;

	public int cur_youdaodan;

	private float guntime;

	private float guntimelimit = 0.2f;

	private float missiletime;

	private float missiletimelimit = 2f;

	private float singlemissiletime;

	private float singlemissiletimelimit = 2f;

	public UILabel machinegunlabel;

	public UILabel missilelabel;

	public UILabel singlemissilelabel;

	public UILabel youdaodanlabel;

	public UISprite machinegunFillSprite;

	public UISprite missileFillSprite;

	public UISprite singlemissileFillSprite;

	public GameObject[] weaponobj;

	public void initinfo(player_weapon curatt)
	{
		gun_max = curatt.machgun_max;
		missile_max = curatt.missile_duo_max;
		singlemissile_max = curatt.missile_max;
		youdaodan_max = curatt.youdaodan;
		if (gun_max != 0)
		{
			guntimelimit = curatt.machgun_fill_time / (float)gun_max;
		}
		if (singlemissile_max != 0)
		{
			UIController.instance.ishavesingle = true;
			singlemissiletimelimit = curatt.missile_fill_time / (float)singlemissile_max;
		}
		else
		{
			UIController.instance.ishavesingle = false;
			NGUITools.SetActive(weaponobj[0], state: false);
		}
		if (missile_max != 0)
		{
			UIController.instance.ishavemultiple = true;
			missiletimelimit = curatt.missile_duo_fill_time / (float)missile_max;
		}
		else
		{
			UIController.instance.ishavemultiple = false;
			NGUITools.SetActive(weaponobj[1], state: false);
		}
		if (curatt.youdaodan == 0)
		{
			NGUITools.SetActive(weaponobj[2], state: false);
		}
		cur_gun = gun_max;
		cur_missile = missile_max;
		cur_singlemissile = singlemissile_max;
		cur_youdaodan = youdaodan_max;
		for (int i = 1; i < 5; i++)
		{
			showweaponnum(i, 0);
		}
	}

	private void Update()
	{
		if (!recgun)
		{
			if (!regunflag)
			{
				gunintertime += Time.deltaTime;
				if (gunintertime >= recintertime)
				{
					regunflag = true;
					gunintertime = 0f;
				}
			}
			else
			{
				guntime += Time.deltaTime;
				if (guntime > guntimelimit)
				{
					showweaponnum(1, 1);
					guntime = 0f;
				}
			}
		}
		if (!recmissile)
		{
			if (!remissileflag)
			{
				missileintertime += Time.deltaTime;
				if (missileintertime >= recintertime)
				{
					remissileflag = true;
					missileintertime = 0f;
				}
			}
			else
			{
				missiletime += Time.deltaTime;
				if (missiletime > missiletimelimit)
				{
					showweaponnum(2, 1);
					missiletime = 0f;
				}
			}
		}
		if (recsinglemissile)
		{
			return;
		}
		if (!recsinglemissileflag)
		{
			singleintertime += Time.deltaTime;
			if (singleintertime >= recintertime)
			{
				recsinglemissileflag = true;
				singleintertime = 0f;
			}
		}
		else
		{
			singlemissiletime += Time.deltaTime;
			if (singlemissiletime > singlemissiletimelimit)
			{
				showweaponnum(3, 1);
				singlemissiletime = 0f;
			}
		}
	}

	public void showweaponnum(int type, int interval)
	{
		switch (type)
		{
		case 1:
			cur_gun += interval;
			if (cur_gun < 0)
			{
				cur_gun = 0;
			}
			if (cur_gun > gun_max)
			{
				cur_gun = gun_max;
			}
			machinegunlabel.text = string.Empty + cur_gun;
			machinegunFillSprite.fillAmount = (float)cur_gun / (float)gun_max;
			if (cur_gun == 0)
			{
				plane_smothfollow.instance.machinegunFlag = false;
			}
			guntime = 0f;
			gunintertime = 0f;
			break;
		case 2:
			cur_missile += interval;
			if (cur_missile < 0)
			{
				cur_missile = 0;
			}
			if (cur_missile > missile_max)
			{
				cur_missile = missile_max;
			}
			missilelabel.text = string.Empty + cur_missile;
			missileFillSprite.fillAmount = (float)cur_missile / (float)missile_max;
			if (cur_missile == 0)
			{
				plane_smothfollow.instance.guidedmissileFlag = false;
			}
			missiletime = 0f;
			missileintertime = 0f;
			break;
		case 3:
			cur_singlemissile += interval;
			if (cur_singlemissile < 0)
			{
				cur_singlemissile = 0;
			}
			if (cur_singlemissile > singlemissile_max)
			{
				cur_singlemissile = singlemissile_max;
			}
			singlemissilelabel.text = string.Empty + cur_singlemissile;
			singlemissileFillSprite.fillAmount = (float)cur_singlemissile / (float)singlemissile_max;
			if (cur_singlemissile == 0)
			{
				plane_smothfollow.instance.singlemissileFlag = false;
			}
			singlemissiletime = 0f;
			singleintertime = 0f;
			break;
		case 4:
			cur_youdaodan += interval;
			if (cur_youdaodan < 0)
			{
				cur_youdaodan = 0;
			}
			if (cur_youdaodan > youdaodan_max)
			{
				cur_youdaodan = youdaodan_max;
			}
			youdaodanlabel.text = string.Empty + cur_youdaodan;
			break;
		}
	}
}
